# _*_coding:utf-8_*_
__author__ = 'gerry'

# recursive function
'''
def calc(n):
    print('-->'), n
    if n / 2.0 > 0:
        return calc(n / 2)
    return n


if __name__ == "__main__":
    print calc(10)
'''


def binary_serach(find_num, data):
    mid = len(data) / 2
    if mid > 0:
        if find_num > data[mid]:
            print("data should in right", mid, data[mid:])
            binary_serach(find_num, data[mid:])
        elif find_num < data[mid]:
            print("data should in left", mid, data[:mid])
            binary_serach(find_num, data[:mid])
        else:
            print("find the num:%s" % data[mid])
    elif data[0] == find_num:
        print("\033[32;1mfind the num :%s\033[0m" % data[mid])
    else:
        print('cannot find the num', find_num)


if __name__ == "__main__":
    binary_serach(12797, range(1000001))
